<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #btn {
            margin: 100px;
        }

        .div1 {
            padding: 100px;
            background-color: #f0f0f0;
        }
    </style>
</head>

<body>
    <button id="btn">click</button>
    <br>
    <input type="text" id="input1">
    <div class="div1">
        <button class="money">充值</button>
    </div>
    <hr>
    <p>获取按键的keycode</p>
    <input type="text" class="key">

    <script>
        btn.onclick = function (e) {
            // window.event 是兼容ie的写法
            var event = e || window.event;
            // target 事件作用的元素
            console.log(event);
        }
        input1.onkeyup = function (e) {
            var e = e || window.event;
            console.log(e.target.value);
        }
        document.body.onclick = function (e) {
            // clientX 点击位置距离浏览器左上角的水平距离
            // clientY 点击位置距离浏览器左上角的竖直距离
            console.log(e.clientX, e.clientY);
            // screenX 距离电脑屏幕左上角的水平距离
            // screenY 距离电脑屏幕左上角的竖直距离
            console.log(e.screenX, e.screenY);
        }
        var div1 = document.querySelector('.div1');
        var btn2 = document.querySelector('.money')
        btn2.onclick = function (e) {
            console.log(e.offsetX, e.offsetY);
        }
        // 通过keycode获取按键的值
        var key = document.querySelector('.key');
        key.onkeyup = function (e) {
            console.log(e.keyCode);
        }
    </script>
</body>

</html>